<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var el = document.getElementsByClassName('bgc')
    console.log(el);
    for (var i = 0; i < el.length; i++){
      el[i].style.backgroundColor = 'red';
    }
    
    var current = new Date();//时间，
    var target = new Date(2023,4,1,00,00,00);//目标时间 
  setInterval(function(){
    current = new Date();
    var diffMs = Math.ceil((target.getTime() - current.getTime()) / 1000);//获取目标时间减去当前时间的毫秒数，并取整
    var day = Math.floor(diffMs / (24 * 60 * 60));
    var hours = Math.floor((diffMs % (24 * 60 * 60)) / (60 *60));
    var minutes = Math.floor((diffMs % (60 * 60)) / 60);
    var seconds = diffMs % 60;
    console.log('距离劳动节还有：',`${day}天${hours}时${minutes}分${seconds}秒`)
  },1000)  
  </script>
</body>
</html>